/* Grogue console source code 
   This is the generic console code - we call whichever console we want to 
   use for our display, all of which implement the Grconsole interface

*/

import {

}

//Creature needs to be an *interface* type here
type Grconsole interface { //this type of console only provides write access - PDF etc implements this
	Init (dbview * DisplayBufferView, depth uint32, font-size uint8, runes []rune, playerview * CreatureView) bool 
	//initialize display - player view pointer for status + inventory display, display buffer view pointer for dimensions, and cell contents queries
	Refresh(db *DisplayBuffer,dirty []coord) bool //refresh dirty cells marked in db
	Dimensions() coord
	ColorDepth() uint32 //the total number of colours?
}

/* A note about the DisplayBuffer format: hexagon and triangle DisplayBuffers have "non-cell" spaces in them 
   in order to fix a triangle or hex layout into a square grid 
	*⊻*⊻*⊻*⊻*
	*⊼*⊼*⊼*⊼*
	⊻*⊻*⊻*⊻*⊻ 
	⊼*⊼*⊼*⊼*⊼ 
	for triangles, for example (where the non-asterisks are not cells). Grconsoles are free to treat the noncells
	as special items - for example, SDL_console colours the equivalent glyph's three subareas with the colours of the 
	cells to the sides of it appropriately, to enhance the effect of the cell looking triangular). ' ' is used for the hexagons because there is no
	appropriate unicode character with the required shape (which would be similar to a Y superposed on an inverted 'Y'). 
*/

type Grconsole_rw interface { //this type of console provides write access and also read access (for controls)
	Grconsole
	Command() Command 
	Item() ItemID
	Coord() Coord
}

//Grconsole_rws also must be allowed to ask the DisplayBuffer about the extended contents of a cell (so they can implement the "passive look" functionality
// while the player is selecting a coordinate).

func PollInput(gc Grconsole_rw) ComSeq {
		command = gc.Command()
		options = make([]interface{},0,2)
		//poll for a command press

		switch {
                //if command is in the "short" range (doesn't need extended info) then just return it
			case command < C_ITEMSELECT:
	        // if command is in the "item" range (needs an item id) then get an item id
			case command < C_COORDSELECT:
				options.append(gc.Item())
                // if command is in the "coord" range then get a coord
			case command < C_ITEMCOORDSELECT:
				options.append(gc.Coord())		
                // if command is in the "item and coord" range then get an item and a coord
			case command < C_EXAMINE:
				options.append(gc.Item())
				options.append(gc.Coord())
                // if command is the Examine command then check our mode and ask for information appropriately
			case command == C_EXAMINE:
				//stuff
			default:
				//UNRECOGNISED COMMAND! SHOULD NEVER HAPPEN
		return ComSeq{command,options}
	}


/* The game loop is, essentially:

	A B DO CLEVER THINKING STUFF
	 if THINK CHANGES DISPLAY: for all Grconsoles: Refresh
        if not PlayerTurn REPEAT B
	for active Grconsole_rw: PollInput
	DO INPUT
	REPEAT A
*/
